//
//  HMEmoticonButton.swift
//  MyWeibo
//
//  Created by apple on 16/5/2.
//  Copyright © 2016年 apple. All rights reserved.
//  自定义button

import UIKit

class HMEmoticonButton: UIButton {

    
    //当前表情按钮对应的表情模型
    var emoticon:HMEmoticon?{
        
        didSet{
            
         //type判断是图片表情还是emoji表情
            if emoticon?.type == "1" {
                //如果是转换成oc字符串 调用分类转换表情
                self.setTitle((emoticon!.code! as NSString).emoji(), forState: UIControlState.Normal)
                //解决复用问题，重新设置图片
                self.setImage(nil, forState: UIControlState.Normal)
            }else{
                //如果不是设置图片表情数据 
                let image = UIImage(named:"\(emoticon?.folderName ?? "")/\(emoticon?.png ?? "")", inBundle: HMEmoticonKeyBoardViewModel.sharedViewModel.emoticonBundle,compatibleWithTraitCollection: nil)
                //设置图片表情
                self.setImage(image, forState: .Normal)
                //设置字体大小
                self.setTitle(nil, forState: UIControlState.Normal)
            }

        }
    }

}
